<?php
/*******************************************************************************
 *
 *  Name: viewincidentview
 *
 *  Date: 05/03/2012
 *  
 *  Description: Shows the user details on a particular incident and allows them
 *               them to assign the incident to a irteam and attach reports
 *  
 *  Author: Hayden Waisanen
 *  
 *  Todo:
 *     NONE
 *
 *  Modification History:  
 * 
 *   Date         Name
 *  ----------   --------------
 *  2012-04-26   HAYDEN WAISANEN
 *  2012-04-25   HAYDEN WAISANEN
 *  2012-04-22   HAYDEN WAISANEN
 * 
 *****************************************************************************/
?>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript">
</script>
<style type="text/css">
.hidden {
   display: none;
}
</style>
<script type="text/javascript">
function attach(ReportID,IncidentID)
{
   $.ajax({
      type: 'POST',
      url: '../../analyst/attachIncident/'+ReportID+'/'+IncidentID+'/',
      success: function(data) {
         $('.'+ReportID).text(data);
         if(data=='Attach')
            $('#report_'+ReportID).addClass('hidden');
         else
            $('#report_'+ReportID).removeClass('hidden');
      },
      error: function() {
         alert("Unable to attach reports at this time.");
      }
});
}
</script>
</head>
<body>

<h3>Incident <?php echo $Incident['IncidentID'].' - '.$Incident['Name'];?></h3>

<?php
//Check for mismatch in analyst
if($user['UserID'] != $Incident['AnalystID'])
   echo "<div style='background-color: yellow;'>Warning: Editing a different analysts incident</div>";
?>

<h4>Description</h4>
<p><?php echo $Incident['AnalystDescription']; ?></p>

<?php if($Incident['AssignedTeam'] != null): ?>


<h4> Tracking Information</h4>
<table border="2px">
<tr>
<td>IR Team</td> 
<td><?php echo $Incident['AssignedTeam']; ?></td>
</tr>
<tr>
<td>Work Started</td>
<td><?php echo $Incident['WorkStarted']; ?></td>
</tr>
<tr>
<td>Work Finished</td>
<td>
<?php 
if($Incident["WorkFinished"] == NULL)
   echo "Unavailable";
else
   echo $Incident['WorkFinished']; 
?>
</td>
</tr>
<tr>
<td>Expected Completition</td>
<td><?php echo $Incident["ExpectedCompletionDate"] ?></td>
</tr>
<tr>
<td>IR Team Notes</td>
<td><?php echo $Incident["IRTeamDescription"]; ?></td>
</tr>
<tr>
<td>Location</td>
<td><?php 
if($Incident['State']!=NULL)
   echo $Incident["Address"].", ".$Incident["City"].", ".$Incident["State"]." ".$Incident["Zipcode"];
else
   echo "TBD";
 ?></td>
</tr>
</table>

<?php endif; ?>

<h4>Connected Reports Summary</h4>
<table border="2px"> 
<tr>
<td>ReportID</td>
<td>CR ID</td>
<td>Location</td>
<td>Attach/Detach</td>
</tr>
<?php
foreach ($Reportsall as $entry)
{
   //Filter out reports assigned to other incidents
   if( $entry["IncidentID"] == NULL || $entry["IncidentID"] == $IncidentID )
   {
      if($entry["IncidentID"] == NULL)
         echo "<tr class='hidden' id='report_".$entry["ReportID"]."'>";
      else
         echo "<tr id='report_".$entry["ReportID"]."'>";

      echo '<td>'.anchor('/analyst/viewreport/'.$entry["ReportID"].'/',$entry["ReportID"]).'</td>';
      echo '<td>'.$entry["CustomerRepID"].'</td>';
      echo '<td>'.$entry["City"].', '.$entry["State"] .'</td>';
      //echo '<td>'.anchor('analyst/attachIncident/'.$entry["ReportID"].'/'.$IncidentID.'/', 'Attach').'</td>';
      if( $entry["IncidentID"] == NULL)
         $AttachStatus = "Attach";
      else
         $AttachStatus = "Detach";
      echo '<td>';
         echo '<button type="button" class="'.$entry["ReportID"].'" onclick="attach('.$entry["ReportID"].','.$IncidentID.')">'.$AttachStatus.' </button>';
      echo "<tr>";
   }
}
?>
</table>


<!--                              Assign to available team                                             -->

<?php if($Incident['AssignedTeam'] == null): ?>

<h4>Assign To Available Team</h4>

<?php echo validation_errors(); ?>

<?php echo form_open('analyst/assignincident'); ?>

<div>
IR Teams:
<!-- IR TEAMs -->
<select name="irteam">
<?php
foreach ($irteams AS $team)
{
   echo "<option value='".$team["UserID"]."'>".$team["UserID"]."</option>";
}
?>
</select>
<input type="hidden" name="IncidentID" value="<?php echo $Incident["IncidentID"]; ?>">
<input type="submit" value="Submit" />
</div>

</form>

<?php endif; ?>


<h4>Reports to attach</h4>

<table border="2px"> 
<tr>
<td>ReportID</td>
<td>CR ID</td>
<td>Location</td>
<td>Attach/Detach</td>
</tr>
<?php
foreach ($Reportsall as $entry)
{
   //Filter out reports assigned to other incidents
   if( $entry["IncidentID"] == NULL || $entry["IncidentID"] == $IncidentID )
   {
      echo "<tr>";
      echo '<td>'.anchor('/analyst/viewreport/'.$entry["ReportID"].'/',$entry["ReportID"]).'</td>';
      echo '<td>'.$entry["CustomerRepID"].'</td>';
      echo '<td>'.$entry["City"].', '.$entry["State"] .'</td>';
      //echo '<td>'.anchor('analyst/attachIncident/'.$entry["ReportID"].'/'.$IncidentID.'/', 'Attach').'</td>';
      if( $entry["IncidentID"] == NULL)
         $AttachStatus = "Attach";
      else
         $AttachStatus = "Detach";
      echo '<td>';
         echo '<button type="button" class="'.$entry["ReportID"].'" onclick="attach('.$entry["ReportID"].','.$IncidentID.')">'.$AttachStatus.' </button>';
      echo "<tr>";
   }
}
?>
</table>
</body>
</html>
